package com.example.list.service_demo;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyService extends Service {
    //onBind为必须实现的抽象方法
    @Override
    public IBinder onBind(Intent arg0) {
        return new MyBinder();
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onRebind(Intent intent) {
        super.onRebind(intent);
    }

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.d("service", "service unbind");
        return super.onUnbind(intent);
    }

    //模拟：定义一些函数，作为业务处理
    public void playPoker() {
        Toast.makeText(this, "玩扑克", Toast.LENGTH_SHORT).show();
    }

    public void playBall() {
        Toast.makeText(this, "打球", Toast.LENGTH_SHORT).show();
    }

    /**
     * 构造一个MyBinder类，其继承于Binder,而Binder实现了IBinder的接口
     */
    public class MyBinder extends Binder {
        //返回Service实例的引用
        public MyService getService() {
            return MyService.this;
        }
    }
}